package tests;

import static org.junit.Assert.*;

import org.jgrapht.graph.*;

import java.util.Random;
import java.util.Vector;

import graphNew.MainGraph;
import io.IoHandler;

import org.jgrapht.graph.DefaultDirectedWeightedGraph;
import org.jgrapht.graph.DefaultWeightedEdge;
import org.jgrapht.graph.DefaultEdge;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import components.Goal;
import components.Operator;
import components.PrePostCond;
import components.PrevailCond;
import components.Variable;

public class MainGraphTest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testMainGraph() {
		Vector<Variable> vars= new Vector<Variable>();
		Vector<Goal> goals= new Vector<Goal>();
		Vector<Operator> operators= new Vector<Operator>();
		
		try {
			IoHandler.ParseFile("input", vars, goals, operators);
		} catch (NumberFormatException e) {
			e.printStackTrace();
			fail("exception heppened");
		} catch (Exception e) {
			e.printStackTrace();
			fail("exception heppened");
		}
		MainGraph mg=new MainGraph(operators);
		
		assertTrue(true);
		int j=0;
		try {
			for(DefaultWeightedEdge i:mg.getMainGraph().edgeSet()){
				Random x=new Random();
				if (j==x.nextInt(5000))
				j++;
				
			
				
			}
		} catch (Exception e) {
			fail("Exception happened");
			e.printStackTrace();
		}
		
	}
	
	@Test
	public void testMainGraph2() {
		Variable v1=new Variable("v1", 5, -1, 0);
		Variable v2=new Variable("v2", 5, -1, 1);
		Variable v3=new Variable("v3", 5, -1, 2);
		try {
			v1.setState(1);
			v2.setState(0);
			v3.setState(0);
		
			PrePostCond p1=new PrePostCond(v3, 0, 4);
			PrePostCond p2=new PrePostCond(v2, 0, 3);
			PrePostCond p3=new PrePostCond(v1, 1, 2);
			PrePostCond p4=new PrePostCond(v3, 0, 5);
			PrevailCond pv=new PrevailCond(v1, 1);
			PrevailCond pv2=new PrevailCond(v2, 0);
			Vector<PrePostCond> prep1= new Vector<PrePostCond>();
			prep1.add(p1);
			prep1.add(p2);
			prep1.add(p3);
			Vector<PrePostCond> prep2= new Vector<PrePostCond>();
			Vector<PrevailCond> prev = new Vector<PrevailCond>();
			prev.add(pv);
			prev.add(pv2);
			
			
			
			Operator o1= new Operator("o1",prep1 , new Vector<PrevailCond>(),1);
			Operator o2= new Operator("o2",prep2 , prev,1);
			
			Vector<Operator> op=new Vector<Operator>();
			op.add(o1);
			op.add(o2);

			Goal g=new Goal(v2, 3);
			
			MainGraph mg=new MainGraph(op);
			
			assertTrue("edges",mg.getMainGraph().edgeSet().size()==1);
			assertTrue("vertex",mg.getMainGraph().vertexSet().size()==2);
			
			System.out.println(mg.getMainGraph().toString());
			
		} catch (Exception e) {
			fail("Exception happened");
			e.printStackTrace();
		}
		
		
		
	}

}
